<!DOCTYPE HTML>
<html>

<head>
  <title>How things are made</title>
  <meta name="description" content="website description" />
  <meta name="keywords" content="website keywords, website keywords" />
  <meta http-equiv="content-type" content="text/html; charset=windows-1252" />
  <link rel="stylesheet" type="text/css" href="style/style.css" title="style" />
</head>
<?php
	session_start();
?>
<body>
      <div id="header">
      <div id="logo">
        <div id="logo_text">
          <!-- class="logo_colour", allows you to change the colour of the text -->
          <h1><a href="index.php">how things are<span class="logo_colour">Made</span></a></h1>
          <h2>Simple.Different.Creative.</h2>
          </div> 
          
         </div>
      <div id="menubar">
        <ul id="menu">
          <!-- put class="selected" in the li tag for the selected page - to highlight which page you're on -->
           <li><a href="index.php">Home</a></li>
           <li><a href="profileread.php">My Profile</a></li>
          <li><a href="addarticle.php">Add Posts</a></li>
          <li class="selected"><a href="searcharticle.php">Search Posts</a></li>
          <li><a href="searchuser.php">Search User</a></li>
          <li><a href="sendEmail.php">Contact Us</a></li>
        </ul>
      </div>
    </div>
    <div id="site_content">
      <div class="sidebar">
        <!-- insert your sidebar items here -->
        <h3>Latest User</h3>
<h4>Click to see the user registered details</h4>
        <h5></h5>
        <p>
        <?php
		DEFINE ('DB_USER', 'root');
		DEFINE ('DB_PASSWORD', '');
		DEFINE ('DB_HOST', 'localhost');
		DEFINE ('DB_NAME', 'SITEDATABASE');
	
		// Make the connection:
		$dbc = @mysqli_connect (DB_HOST, DB_USER,DB_PASSWORD, DB_NAME) 
		OR die ('Could not connect to MySQL: ' .mysqli_connect_error());

		
		
		$q = "select * from users ORDER BY registrationtime DESC LIMIT 1";
		$r = @mysqli_query($dbc,$q);
		if($r)
		{
			
			$row=mysqli_fetch_array($r,MYSQLI_ASSOC);
			

			echo "Fetchiung the name of ".$row['fname']."";
	        echo '<p>Click here to see user details<br /><a href="http://localhost/MyBlog/showuser.php?other_user_id='.$row['user_id'].'">'.$row['fname'].' '.$row['lname'].'</a></p>';
			echo "Query Executed";			
    	    echo '<p></p>';
		}
		else
		{
			echo "Error in query";
		}
		mysqli_free_result ($r);//Free the resources
		?>
        </p>
        <p></p>
        <h4>Sponsored Links</h4>
        <h5></h5>
        <p>This space is reserved for 5 advertisement links</p>
        <h3>Social Media Links</h3>
        <ul>
          <div class="footer_text">
         <div class="foot_pad">
          <div class="link1"><a href="http://www.facebook.com/pages/How-Things-Are-Made/377142059843?sk=wall"> Be a fan on Facebook</a></div>
          <div class="link2"><a href="#">Follow us on Twitter</a></div>
          <div class="link3"><a href="logout.php">Logout</a></div>
          </div>
          </div>
        </ul>
        
      </div>
      <div id="content">
        <!-- insert the page content here -->
        <?php
        	if(!$_SESSION['email'])
		{
	
			header("Location: http://localhost/MyBlog/login.php");
		
		}
		else
		{
            if(isset($_POST['submitted']))
            {
                $comment_content = $_REQUEST['comment_content'];
                $user_email=$_SESSION['email'];
                $post_id = $_REQUEST['post_id'];
                
                $q="insert into user_comment(post_id,user_email,comment_content) VALUES('$post_id','$user_email','$comment_content')"; 
                $r=@mysqli_query($dbc,$q);
                if($r)
                {
                    echo "Post submitted";
                    //header("Location: http://localhost/MyBlog/showarticle.php?post_id='$post_id'");
                }
                else
                {
                    echo "Post not submitted";
                }
                
                
            }
            
			$post_id = $_REQUEST['post_id'];
			echo "The post is opening";
			echo $post_id;
			
			
			
			$q="select * from userposts where `post_id`='".$post_id."'";
			$r=@mysqli_query($dbc,$q);
			
			if($r)
			{
				$row=mysqli_fetch_array($r);
				$user_email=$row['user_email'];
				$subject=$row['subject'];
				$content=$row['content'];
				$submit_time=$row['submit_time'];
				$image_name=$row['image_name'];
				?>
				
				<table>
				<?php echo $subject; ?>
				<tr>
				<th>Author</th>
				<th><div align="center">Content</div></th>
				<th>Time</th>
				</tr>
				
				<tr>
				<td><?php echo $user_email; ?></td>
				<td><?php echo $content; ?></td>
				<td><?php echo $submit_time; ?></td>
				</tr>
				 <?php
					//THis loop is to add comement on the article
					
					$q="select * from user_comment where `post_id`='".$post_id."'";
					$r=@mysqli_query($dbc,$q); 
					if($r)
					{				
						while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
						{
							echo '<tr>
								<td>'.$row['user_email'].'</td>
								<td>'.$row['comment_content'].'</td>
								<td>'.$row['comment_time'].'</td>
								</tr>';
								
						}
					}
					else 
					{
						echo "No comments received";
					}
					?>
                    </table>
				 <?php	
				 }
				}
					
			 ?>
        
       		<form action="showarticle.php?post_id=<?php echo $post_id ?>" method="post">
			Comment<textarea name="comment_content" rows="10" cols="55"></textarea>
			<input type="submit" value="Add Comment" />
			<input type="hidden" name="submitted" value="1" />
			</form>
            
       
      </div>
    </div>
    <div id="content_footer"></div>
    <div id="footer">
      Copyright &copy; 2011 | howthingsaremade.com <a href=" ></a> | <a href="" ></a> | <a href=" ></a>
    </div>
  </div>
<div style="text-align: center; font-size: 0.75em;">  <a href="	http://facebook.com/howthingaremade.com"> Designed for E-Business</a>.</div></body>
</html>
